<template>
  <div class="article-add">
    <!-- 文章添加与修改组件 -->
    <el-dialog title="添加文章" :visible.sync="addDialogTableVisible" @close="addDialogclose" :before-close="addDialogclose">
      <el-form
        :model="addArticleForm"
        :rules="addArticleFormRules"
        ref="addArticleFormRef"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="文章标题" prop="title">
          <el-input v-model="addArticleForm.title" placeholder="请输入文章标题"></el-input>
        </el-form-item>
        <el-form-item label="文章内容" prop="articleBody">
          <quill-editor v-model="addArticleForm.articleBody" ref="myQuillEditor"></quill-editor>
        </el-form-item>
        <el-form-item label="视频地址">
          <el-input v-model="addArticleForm.videoURL" placeholder="请输入视频地址"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogclose">取 消</el-button>
        <el-button type="primary" @click="surearticle">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { add, update } from "@/api/hmmm/articles"// 引入接口
export default {
  name: 'articleAdd',
  props: {
    addDialogTableVisible: {
      type: Boolean
    }
  },
  data() {
    return {
      // 添加文章数据
      addArticleForm: {
        title: '',
        articleBody: '',
        videoURL: ''
      },
      // 富文本编辑器验证规则
      addArticleFormRules: {
        title: [{ required: true, message: '请输入活动名称', trigger: 'blur' },
        { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }],
        articleBody: [{ required: true, message: '请输入活动名称', trigger: 'blur' },
        { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }],
        videoURL: [{ required: false, message: '请输入活动名称', trigger: 'blur' }]
      },

    }
  },
  methods: {
    //关闭重置验证规则
    addDialogclose() {
      // 强制视频地址为空
      this.addArticleForm.videoURL = ''
      this.$refs.addArticleFormRef.resetFields()
      this.$emit('closedialog')
    },
    // 点击确定新增技巧
    surearticle() {
      this.$refs.addArticleFormRef.validate(async valid => {
        if (!valid) return
        const data = await add(this.addArticleForm
        )
        this.$message.success('发表文章成功')
        this.$emit('closedialog')
        this.$emit('getlist')
      })
    },
  },

}
</script>

<style scoped lang='less'>
</style>
